#1.
person_info={
    "name":"Alex",
    "age":30,
    "country":"USA",
    "Language":["English","Spanish"],
    "is_student":False
}
print(person_info["name"])
#2.
person_info["age"] = 30
#3.
person_info["height"] = 175
print(person_info)
#4.
del person_info["is_student"]
print(person_info)
#5.
for e in person_info.items():
    print(e,end = ' ')
print()
#6.
# 检查并添加 email
if "email" not in person_info:
    person_info["email"] = "alex@example.com"
print(person_info)
#7.
person_info['Language'] = ['English']
print(person_info)
#8.
print(len(person_info['Language']))
#9.
person_info['Language'].append('French')
print(person_info)
#10.
for i in range(1,4):
    person_info[f'hobby{i}'] = i
print(person_info)

#二.进阶题
#1.
employees = {
    101:{
        "name":"Alice",
        "age":30,
        "gender":"Female",
        "postion":"Data Scientist",
        "team":"Research",
        "salary_history":[70000,80000,90000]
    },
}
employees[102] = {
        "name":"Jack",
        "age":32,
        "gender":"male",
        "postion":"Data Scientist",
        "team":"Research",
        "salary_history":[70000,80000,90000]
}
print(employees)
#2.
del employees[102]
print(employees)
#3.
employees[101]["age"] = 31
print(employees)
#4.
employees[101]["salary_history"].append(95000)
print(employees)
#5.
avg = str(sum(employees[101]["salary_history"]) / len(employees[101]["salary_history"]))
print('平均薪资为：'+avg)
#6.
# # 方法2：使用循环（更易读）
older_employees_list = []
for emp_id, emp_info in employees.items():
    if emp_info["age"] > 25:
        older_employees_list.append((emp_id, emp_info["name"]))
print(older_employees_list)
#7.
for emp_id, emp_info in employees.items():
    # 获取最新薪资（salary_history列表最后一个元素）
    latest_salary = emp_info["salary_history"][-1]
    # 计算奖金（最新薪资的10%）
    bonus = latest_salary * 0.10
    # 添加 bonus 键
    emp_info["bonus"] = round(bonus, 2)  # 保留两位小数
print(employees)
#8.
employees[101]['postion'] = 'Senior Data Scientist'
print(employees)
#9.
for  emp_id, emp_info in employees.items():
    del employees[emp_id]['gender']
print(employees)
#10.
new_dict = {}
for emp_id, emp_info in employees.items():
    new_dict[emp_id] = {
        "name": emp_info["name"],
        "position": emp_info["postion"]
    }
print(new_dict)